package com.atguigu.gmall.order.config;

import com.atguigu.gmall.constant.MqConst;
import org.checkerframework.checker.units.qual.C;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author mgx
 * @create 2024-09-04 11:08
 * @Description 取消订单延迟插件队列配置
 */
@Configuration
public class OrderCancelMqConfig {


    /**
     * 延迟队列
     * @return
     */
    @Bean
    public Queue delayQueue() {
        return new Queue(MqConst.QUEUE_ORDER_CANCEL, true);
    }

    /**
     * 延迟插件的交换机配置
     * @return
     */
    @Bean
    public CustomExchange delayExchange() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");

        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL, "x-delayed-message", true, false, map);
    }


    /**
     * 绑定关系
     * @return
     */
    @Bean
    public Binding bindingDelay() {
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }


}
